import { fileURLToPath, URL } from 'node:url'
import path from "path";
import AutoImport from 'unplugin-auto-import/vite'
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

import { defineConfig,loadEnv  } from 'vite'
import vue from '@vitejs/plugin-vue'
import inject from '@rollup/plugin-inject'
 

const pathSrc = path.resolve(__dirname, "src");
// https://vitejs.dev/config/
export default defineConfig(({ command, mode })=>{
  return {
    plugins: [
      vue(),

      inject({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery",
      }),
      AutoImport({ 
        // 自动导入 相关 组件
        imports: ['vue', 'vue-router','pinia'],
        resolvers: [
          ElementPlusResolver(),
        ],
        
        dts: path.resolve(pathSrc, "auto-imports.d.ts")
       }),
       Components({
        dirs: ['src/components'], // 要搜索组件的目录
        extensions: ['vue'],// 组件有效扩展名
        resolvers: [
          
          // Auto register Element Plus components
          // 自动导入 Element Plus 组件
          ElementPlusResolver()
        ],
        dts: path.resolve(pathSrc, "components.d.ts")
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      disableHostCheck: true,
      open: true,
      hotOnly: true,
      host: "0.0.0.0",
      proxy: {
        "/gateway": {
          // target: "https://pre.91medicine.net",
          target: "https://pre-conserve-gt.91medicine.net/",
          // target: "https://dev.91medicine.net",
          // target: "http://adam-yoga14s:12333",
          // target: "https://cloud.91medicine.cn",
          // target: "http://adam-yoga14s:12333",
          //   target: "http://192.168.0.148:12333",
          changeOrigin: true,
        },
      },
    },
    base: "./",
  }

});
